#ifndef TR_COMMON_H
#define TR_COMMON_H

#include <cnetsupport.h>
#include "tr_definitions.h"

// NODE utility functions
static NODE *new_node(const CnetAddr, VECTOR *);
static NODE *get_node(const CnetAddr, VECTOR *);

// WINDOW utility functions
static void add_packet(PACKET *, WINDOW *);
static PACKET *get_packet(const uint16_t, WINDOW *);
static PACKET *remove_packet(const uint16_t, WINDOW *);
static void add_id(PACKET_ID *, WINDOW *);
static PACKET_ID *get_id(const uint16_t, WINDOW *);
static PACKET_ID *remove_id(const uint16_t, WINDOW *);
static PACKET *next_packet(WINDOW *);
static PACKET *remove_next_packet(WINDOW *);
static bool window_full(WINDOW *);
static bool window_free(WINDOW *);
static bool window_ready(WINDOW *);
static bool in_window(PACKET *, WINDOW *);

// ACK_PENDING utility functions
static void add_ack(PACKET *, bool, NODE *);
static ACK_PENDING *remove_next_ack(NODE *);

// Checksum functions
static uint16_t head_crc(PACKET *);
static uint16_t msg_crc(PACKET *);

#endif

